package com.test.demo.mapper;

import com.test.demo.pojos.Card;
import com.test.demo.pojos.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CardMapper {
//    @Results({@Result(column = "cid",property = "id"),
//              @Result(column = "ccn",property = "cardNum"),
//              @Result(column = "pid",property = "student" ,
//                      javaType = Student.class,
//                      one = @One(select = ""))  //这里的值为select方法的全路径 如：从com.itheima.mapper.StudentMapper.selectById
//    })
//    @Select("select c.pid ,c.card_num ccn , s.student_name ssn, s.student_age ssa from card c left join student s on c.pid = s.id ")
//    List<Card> selectAll();

    List<Card> selectAll();

    //注解的一对多跟一对一的写法是几乎一样的，只是把@One注解换位@Many注解 其中写为 javaType = List.class 其余不变
    //注解的多对多写法跟一对多的写法一摸一样，只是调用select方发注解上面的select语句不一样而已
    @Results({@Result(column = "ccn", property = "cardNum"),
              @Result(column = "pid", property = "student",
                    javaType = Student.class,
                    one = @One(select = "com.test.demo.mapper.StudentMapper.selectById"))  //这里的值为select方法的全路径 如：从com.itheima.mapper.StudentMapper.selectById
    })
    @Select("select pid , card_num ccn  from card ")
    List<Card> selectAllByAnnotation();

}
